<template>
  <div>
    <Head />
    <div class="login">
      <div class="login_right">
        <p class="login_right_top">关于</p>
        <p style="line-height: 30px">CNode：Node.js专业中文社区</p>
        <p style="line-height: 40px">在这里你可以：</p>
        <ul>
          <li>向别人提出你遇到的问题</li>
          <li>帮助遇到问题的人</li>
          <li>分享自己的知识</li>
          <li>和其它人一起进步</li>
        </ul>
      </div>
      <div class="login_left">
        <p class="login_left_top" style="font-size: 14px; color: #999">
          <router-link to="/"
            ><span class="login_left_top_span">主页</span></router-link
          >
          &nbsp;/ &nbsp;注册
        </p>
        <div class="login_left_form">
          <el-form
            :model="ruleForm"
            :rules="rules"
            :hide-required-asterisk="true"
            ref="ruleForm"
            label-width="100px"
            class="demo-ruleForm"
          >
            <el-form-item label="用户名" prop="name">
              <el-input v-model="ruleForm.name" style="width: 280px"></el-input>
            </el-form-item>
            <el-form-item label="密码" prop="pass">
              <el-input
                type="password"
                v-model="ruleForm.pass"
                style="width: 280px"
                show-password
              ></el-input>
            </el-form-item>
            <el-form-item>
              <el-button type="primary" @click="submitForm('ruleForm')"
                >注册</el-button
              >
              <el-button type="primary" plain @click="resetForm('ruleForm')"
                >通过 GitHub 登录</el-button
              ><a
                href="javascript:;"
                style="margin-left: 15px; color: rgb(141, 128, 151)"
                >忘记密码了？</a
              >
            </el-form-item>
          </el-form>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import Head from "../components/Head.vue";
export default {
  components: { Head },
  data() {
    return {
      ruleForm: {
        name: "",
        pass: "",
      },
      rules: {
        name: [{ required: true, message: "请输入用户名", trigger: "blur" }],
        pass: [{ required: true, message: "请输入密码", trigger: "blur" }],
      },
    };
  },
  methods: {
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.axios
            .post("/register", this.ruleForm)
            .then((res) => {
              if (res.data.results.code != 200) {
                this.$message.error(res.data.results.message);
              } else {
                this.$router.push("/signin");
                this.$message({
                  message: res.data.results.message,
                  type: "success",
                });
              }
            })
            .catch((error) => {
              console.log(error);
              this.$message.error(error.message);
            });
        } else {
          return false;
        }
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },
  },
};
</script>

<style>
.login {
  width: 90%;
  height: 500px;
  margin: auto;
  padding-top: 26px;
}
.login_left {
  margin-right: 305px;
  height: 300px;
  background: #ffffff;
}
.login_right {
  float: right;
  width: 290px;
  padding-bottom: 20px;
  background: #ffffff;
}
.login_right * {
  padding-left: 10px;
}
.login_left_top,
.login_right_top {
  height: 40px;
  background: #f5f5f5;
  line-height: 40px;
  padding-left: 10px;
}
.login_right ul {
  list-style: inside;
  padding-left: 10px;
}
.login_right ul li {
  line-height: 30px;
}
.login_left_top_span {
  color: #80bd01;
}
.login_left_top_span:hover {
  text-decoration: underline;
}
.login_left_form {
  margin-top: 40px;
  width: 450px;
}
.el-form-item__content::after {
  clear: none;
}
.el-form-item::after {
  clear: none;
}
@media screen and (max-width: 980px) {
  .login_right {
    display: none;
  }
  .login_left {
    width: 100%;
  }
  .head_ul {
    clear: both;
    float: none;
  }
  .login {
    width: 98%;
  }
}
</style>